package com.exam.controller;
import com.exam.entity.DataDictionaryType;
import com.exam.service.DataDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/data-dictionary-types")
public class DataDictionaryTypeController {

    @Autowired
    private DataDictionaryTypeService dataDictionaryTypeService;

    @PostMapping
    public ResponseEntity<DataDictionaryType> create(@RequestBody DataDictionaryType dataDictionaryType) {
        DataDictionaryType created = dataDictionaryTypeService.create(dataDictionaryType);
        return ResponseEntity.ok(created);
    }

    @PutMapping("/{id}")
    public ResponseEntity<DataDictionaryType> update(@PathVariable Long id, @RequestBody DataDictionaryType dataDictionaryType) {
        DataDictionaryType updated = dataDictionaryTypeService.update(id, dataDictionaryType);
        return ResponseEntity.ok(updated);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        dataDictionaryTypeService.delete(id);
        return ResponseEntity.noContent().build();
    }

    @GetMapping("/{id}")
    public ResponseEntity<DataDictionaryType> findById(@PathVariable Long id) {
        DataDictionaryType dataDictionaryType = dataDictionaryTypeService.findById(id);
        return ResponseEntity.ok(dataDictionaryType);
    }

    @GetMapping
    public ResponseEntity<List<DataDictionaryType>> findAll() {
        List<DataDictionaryType> dataDictionaryTypes = dataDictionaryTypeService.findAll();
        return ResponseEntity.ok(dataDictionaryTypes);
    }

}